<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Coa_cabang extends Authenticated_Controller{
	function __construct() {
		parent::__construct();
		$this->load->model('coa_cabang_model','coa_cabang');
	}
	
	function index(){
		$this->list_coa_cabang();
	}
	
	function list_coa_cabang(){
		$data['daftar_coa_cabang'] = $this->coa_cabang->get_all();
		$this->load->view('template/header_view');
		$this->load->view('coa_cabang/daftar_coa_cabang',$data);
		$this->load->view('template/footer_view');
	}
	
	function form_add_coa_cabang(){
		$data['daftar_cabang'] = $this->coa_cabang->get_cabang();
		$this->load->view('template/header_view');
		$this->load->view('coa_cabang/form_add_coa_cabang',$data);
		$this->load->view('template/footer_view');
	}
	
	function process_add_coa_cabang(){
                $array = $this->coa_cabang->get_cabang_one($_POST['cabang']);
                $_POST['nama_cabang'] = $array['Nama'];
		$this->coa_cabang->insert_new($_POST);
		redirect(COAC);
	}
	
	function process_delete_coa_cabang($id){
		$this->coa_cabang->delete_old($id);
		redirect(COAC);
	}
	
	function form_edit_coa_cabang($id){
		$data = $this->coa_cabang->get_one($id);
		$data['daftar_cabang'] = $this->coa_cabang->get_cabang();
		$this->load->view('template/header_view');
		$this->load->view('coa_cabang/form_edit_coa_cabang',$data);
		$this->load->view('template/footer_view');
	}
	
	function process_edit_coa_cabang($id){
		$_POST['nama_cabang'] = $this->coa_cabang->get_cabang_one($_POST['cabang']);
		$_POST['nama_cabang']=$_POST['nama_cabang']['Nama'];
		$this->coa_cabang->update_old($id,$_POST);
		redirect(COAC);
	}
}